﻿@page "/admin/vlmanage"
@layout AdminLayout
@attribute [Authorize]
@inject HttpClient HttpClient
@inject IPopupService PopupService

<PageTitle>链接管理</PageTitle>


<div style="display: -webkit-box;">
    @*分类下拉框*@
    <MSelect HideDetails="@true" MinWidth="135" Clearable="@true" Label="分类" Placeholder="请选择分类" Solo Dense
        TItem="VcateSelectItem" TItemValue="string" TValue="string" Items="@vcateSelectItems" ItemText="u => u.Label"
        ItemValue="u => u.Value" Style="margin-right: 20px;width: 120px;"
        OnSelectedItemUpdate="@(e=>VcateSelectedChange(e.Value))" OnClearClick="ClearVcate">
    </MSelect>
    @*视频下拉框*@
    <MSelect HideDetails="@true" MinWidth="200" Label="视频" Placeholder="请选择视频" Solo Dense TItem="VideoSelectItem"
        TItemValue="string" TValue="string" Items="@videoSelectItems" ItemText="u => u.Name" ItemValue="u => u.Id"
        Style="margin-right: 20px;width: 120px;" OnSelectedItemUpdate="@(e=>VideoSelectedChange(e.Id))">
    </MSelect>

    <MButton Color="primary" OnClick="ShowAddForm">
        <MIcon Left>mdi-plus</MIcon>
        添加
    </MButton>
</div>

@*数据表格*@
<MDataTable FixedRight Headers="headers" Items="vlinkList" Width="@("100%")" ItemKey="r=>r.Name" Class="elevation-3"
    Style="height: 550px; overflow-y: auto;margin-top: 15px;">
    <ItemColContent>
        @if (context.Header.Value == nameof(TableViewModel.Id))
        {
            @context.Item.Id
        }
        else if (context.Header.Value == nameof(TableViewModel.Url))
        {
            <div class="text-truncate" style="width: 200px;">@context.Value</div>
        }
        else if (context.Header.Value == nameof(TableViewModel.RealUrl))
        {
            <div class="text-truncate" style="width: 200px;">@context.Value</div>
        }
        else if (context.Header.Value == "actions")
        {
            <MIcon Small Class="mr-2" OnClick="()=>EditItem(context.Item)">mdi-pencil</MIcon>
            <MIcon Small OnClick="()=>DeleteItem(context.Item.Id)">mdi-delete</MIcon>
        }
        else
        {
            @context.Value
        }
    </ItemColContent>

</MDataTable>



@* 编辑对话框 *@
<MDialog @bind-Value="_dialogEdit" MaxWidth="600">
    <MCard>
        <MCardTitle>
            <span class="text-h5">编辑</span>
        </MCardTitle>
        <MCardText>
            <MContainer>
                <MTextField TValue="string" @bind-Value="_editedItem.Name" Label="名称" Placeholder="名称" TextColor="green"
                    HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_editedItem.Url" Label="Url" Placeholder="Url"
                    TextColor="green" HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_editedItem.RealUrl" Label="播放地址" TextColor="green"
                    HideDetails="@true"></MTextField>
            </MContainer>
        </MCardText>

        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="Close">
                取消
            </MButton>
            <MButton Color="blue darken-1" Text OnClick="SubmitEdit">
                提交
            </MButton>
        </MCardActions>
    </MCard>
</MDialog>


@* 添加对话框 *@
<MDialog @bind-Value="_dialogAdd" MaxWidth="600">
    <MCard>
        <MCardTitle>
            <span class="text-h5">添加</span>
        </MCardTitle>
        <MCardText>
            <MContainer>
                <MTextField TValue="string" @bind-Value="_addItem.Name" Label="名称" Placeholder="名称" TextColor="green"
                    HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_addItem.Url" Label="Url" Placeholder="Url" TextColor="green"
                    HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_addItem.RealUrl" Label="播放地址" TextColor="green"
                    HideDetails="@true"></MTextField>

            </MContainer>
        </MCardText>

        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="Close">
                取消
            </MButton>
            <MButton Color="blue darken-1" Text OnClick="SubmitAddAsync">
                提交
            </MButton>
        </MCardActions>
    </MCard>
</MDialog>


@* 删除对话框 *@
<MDialog @bind-Value="_dialogDelete" MaxWidth="500">
    <MCard>
        <MCardTitle Class="text-h6">确定要删除此项吗?</MCardTitle>
        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="CloseDelete">取消</MButton>
            <MButton Color="blue darken-1" Text OnClick="DeleteItemConfirmAsync">确定</MButton>
            <MSpacer></MSpacer>
        </MCardActions>
    </MCard>
</MDialog>
